unit fmShapeWiz ;

interface

uses
  Windows,
  Messages,
  SysUtils,
  Variants,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  SpTBXControls,
  TBXDkPanels,
  StdCtrls,
  SpTBXEditors,
  ActnList,
  uBasic,
  uObjects ;

type
  TMedaFootprintStyle = (
    fpsBGA,
    fpsDIP,
    fpsPGA,
    fpsPLCC,
    fpsPQFP,
    fpsQFN,
    fpsSOIC,
    fpsSOJ,
    fpsSOT,
    fpsTQFP,
    fpsTSSOP,
    fpsVQFP
    ) ;

  TfrmShapeWiz = class( TFrame )
    pnlMain : TSpTBXPanel ;
    SpTBXPanel2 : TSpTBXPanel ;
    btCancel : TSpTBXButton ;
    btOK : TSpTBXButton ;
    btApply : TSpTBXButton ;
    SpTBXPanel3 : TSpTBXPanel ;
    SpTBXGroupBox5 : TSpTBXGroupBox ;
    seMajorGridX : TSpTBXSpinEdit ;
    seMajorGridY : TSpTBXSpinEdit ;
    SpTBXGroupBox1 : TSpTBXGroupBox ;
    seFPSizeX : TSpTBXSpinEdit ;
    seFPSizeY : TSpTBXSpinEdit ;
    SpTBXGroupBox2 : TSpTBXGroupBox ;
    seMinorGridX : TSpTBXSpinEdit ;
    seMinorGridY : TSpTBXSpinEdit ;
    SpTBXGroupBox3 : TSpTBXGroupBox ;
    sePadSizeX : TSpTBXSpinEdit ;
    sePadSizeY : TSpTBXSpinEdit ;
    SpTBXGroupBox4 : TSpTBXGroupBox ;
    seNumber : TSpTBXSpinEdit ;
    SpTBXPanel1 : TSpTBXPanel ;
    rgStyle : TSpTBXRadioGroup ;
    SpTBXGroupBox6 : TSpTBXGroupBox ;
    SpTBXCheckBox2 : TSpTBXCheckBox ;
    SpTBXCheckBox3 : TSpTBXCheckBox ;
    rgPadType : TSpTBXRadioGroup ;
    SpTBXGroupBox7 : TSpTBXGroupBox ;
    seName : TSpTBXEdit ;
    btWiz : TSpTBXButton ;
    cbOptions1: TSpTBXCheckBox;
    procedure btWizClick( Sender : TObject ) ;
    procedure btApplyClick( Sender : TObject ) ;
    procedure btOKClick( Sender : TObject ) ;
  private
    fShape : TMedaShape ;
    procedure SetShape( const Value : TMedaShape ) ;
  public
    property Shape : TMedaShape read fShape write SetShape ;
  end ;

implementation

{$R *.dfm}
uses
  GDIPAPI,
  GDIPOBJ ;

procedure TfrmShapeWiz.SetShape( const Value : TMedaShape ) ;
begin
  fShape := Value ;
end ;

procedure TfrmShapeWiz.btApplyClick( Sender : TObject ) ;
var
  x, y              : extended ;
  i, j, n           : integer ;
  iStack            : TMedaStack ;
  iPad              : TMedaPad ;
begin
  x := seFPSizeX.Value ;
  y := seFPSizeY.Value ;
  Shape.Outline := MakeRect( -x / 2, -y / 2, x, y ) ;
  case TMedaFootprintStyle( rgStyle.ItemIndex ) of
    fpsBGA : begin
        n := Round( sqrt( seNumber.ValueAsInteger ) ) ;
        for i := 0 to n - 1 do
          for j := 0 to n - 1 do begin
            iStack := Shape.AddStack ;
            iStack.Designator :=
              'ABCDEFGHJKLMNPQRSTUVWXYZ'[ i + 1 ] + IntToStr( j + 1 ) ;
            x := ( -( n - 1 ) / 2 + i ) * seMinorGridX.Value ;
            y := ( -( n - 1 ) / 2 + j ) * seMinorGridY.Value ;
            iStack.Offset := MakePoint( x, y ) ;
            iPad := iStack.AddPad ;
            iPad.PadType := TMedaPadType( rgPadType.ItemIndex + 1 ) ;
          end ;
      end ;
    fpsDIP : begin
      end ;
    fpsPGA : begin
      end ;
    fpsPLCC : begin
      end ;
    fpsPQFP : begin
      end ;
    fpsQFN : begin
      end ;
    fpsSOIC : begin
      end ;
    fpsSOJ : begin
      end ;
    fpsSOT : begin
      end ;
    fpsTQFP : begin
      end ;
    fpsTSSOP : begin
      end ;
    fpsVQFP : begin
      end ;
  end ;
end ;

procedure TfrmShapeWiz.btOKClick( Sender : TObject ) ;
begin
  btApplyClick( Sender ) ;
end ;

procedure TfrmShapeWiz.btWizClick( Sender : TObject ) ;
var
  iCount, iCountX, iCountY : integer ;
begin
  iCount := seNumber.ValueAsInteger ;
  case TMedaFootprintStyle( rgStyle.ItemIndex ) of
    fpsBGA : begin
        iCountX := Round( sqrt( iCount ) ) ;
        iCountY := iCount div iCountX ;
        seFPSizeX.Value := ( iCountX + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( iCountY + 2 ) * seMinorGridY.Value ;
      end ;
    fpsDIP : begin
        seFPSizeX.Value := ( iCount + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
    fpsPGA : begin
        seFPSizeX.Value := ( iCount + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
    fpsPLCC : begin
        seFPSizeX.Value := ( iCount + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
    fpsPQFP : begin
        seFPSizeX.Value := ( iCount + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
    fpsQFN : begin
        seFPSizeX.Value := ( iCount + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
    fpsSOIC : begin
        seFPSizeX.Value := ( iCount + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
    fpsSOJ : begin
        seFPSizeX.Value := ( seNumber.Value + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
    fpsSOT : begin
        seFPSizeX.Value := ( seNumber.Value + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
    fpsTQFP : begin
        seFPSizeX.Value := ( seNumber.Value + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
    fpsTSSOP : begin
        seFPSizeX.Value := ( seNumber.Value + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
    fpsVQFP : begin
        seFPSizeX.Value := ( seNumber.Value + 2 ) * seMinorGridX.Value ;
        seFPSizeY.Value := ( 2 + 2 ) * seMajorGridY.Value ;
      end ;
  end ;
end ;

end.

